package com.gpf.marketing.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gpf.marketing.mapper.AdvPositionMapper;
import com.gpf.marketing.pojo.entity.AdvPosition;
import com.gpf.marketing.pojo.vo.AdvPoVo;
import com.gpf.marketing.service.AdvPositionService;
import com.seventh.common.pojo.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: clms-fifth
 * @description: 广告位置业务层
 * @author: 龚鹏飞
 * @create: 2021-07-21 18:32
 **/
@Service
public class AdvPositionServiceImpl implements AdvPositionService {
    @Resource
    private AdvPositionMapper advertPositMapper;


    @Override
    public R selectAdvPosit( Integer currentPage,Integer pageSize, AdvPoVo advPoVo) {
        Page<AdvPosition> page = new Page<>(currentPage,pageSize);
        QueryWrapper<AdvPosition> wrapper = new QueryWrapper();
        if (StringUtils.isNotEmpty(advPoVo.getName())){
            wrapper.like("name",advPoVo.getName());
        }
        Page page1=advertPositMapper.selectPage(page,wrapper);
        return R.ok().put("records",page1.getRecords()).put("total",page1.getTotal());
    }

    @Override
    public R insertAdvPosit(AdvPosition advPosit) {
        int i=advertPositMapper.insert(advPosit);
        return (i>0)? R.ok(): R.error();
    }

    @Override
    public R updateAdvPosit(AdvPosition advPosit) {
        int i=advertPositMapper.updateById(advPosit);
        return (i>0)? R.ok(): R.error();
    }

    @Override
    public R deleteById(Integer id) {
        int i=advertPositMapper.deleteById(id);
        return (i>0)? R.ok(): R.error();
    }

    @Override
    public R selectById(Integer id) {
        AdvPosition advPosition=advertPositMapper.selectById(id);
        return R.ok().put("advPosition",advPosition).put("message","修改成功");
    }
    //下拉
    @Override
    public List<AdvPosition> findAllId() {
        return advertPositMapper.selectList(null);
    }


}
